<template>
	<view class="flex flex-x-b flex-y-center" :class="scroll?'scroll flex-x-start':''"
		:style="{height,'padding-bottom':paddingB}">
		<template v-if="!scroll">
			<view @tap="channge(key)" style="height: 100%;" class="flex flex-y-center" v-for="(item,key) in list"
				:key="key">

				<view class="tabs-item" style="white-space: nowrap;" :style="tab_index == key ?'':';'"
					:class="tab_index == key ?'tab-active':''">{{item.name}}</view>

				<view v-if="item.name == '全部' && ReadCount !== 0" style="background-color: #ff3c5e;width: 35rpx;height: 35rpx;line-height: 35rpx;color: #fff;font-size: 12px;
				border-radius: 50%;text-align: center;margin-left: -10rpx;margin-top: -20rpx;">{{ReadCount}}</view>

			</view>
		</template>

		<template v-else>
			<view @tap="channge(key)" style="height: 100%;" class="flex flex-y-center " v-for="(item,key) in list"
				:key="key">
				<view class="tabs-item" style="margin-right: 48rpx;" :class="tab_index == key ?'tab-active':''"
					:style="tab_index == key && activeColor ?('color:' + activeColor +';'):''">
					{{item.name}}
				</view>
			</view>
		</template>

	</view>
</template>

<script>
	export default {
		name: "tabs",
		props: {
			ReadCount: {
				type: Number,
				default: 0,
			},
			list: {
				type: Array,
				default: () => {
					return []
				}
			},
			height: {
				type: String,
				default: '100rpx'
			},
			index: {
				type: Number,
				default: 0,
			},
			//下边距
			paddingB: {
				type: String,
				default: '0rpx'
			},
			//是否可左右滑动
			scroll: {
				type: Boolean,
				default: false,
			},
			line: {
				type: Boolean,
				default: true,
			},
			color: {
				type: String,
				default: ''
			},
			activeColor: {
				type: String,
				default: ''
			},

		},
		created() {
			this.tab_index = this.index;
		},
		data() {
			return {
				tab_index: 0,
			};
		},
		methods: {
			channge(index) {
				this.tab_index = index;
				this.$emit('change', index);
			}
		}
	}
</script>

<style lang="scss">
	.tabs-item {
		font-size: 28rpx;
		color: #666666;
		font-weight: 400;
		position: relative;
		line-height: 34rpx;
	}

	.tab-active {
		color: $color;
		font-size: 28rpx;
		// font-weight: bold;
	}

	.tab-active::before {
		position: absolute;
		content: '';
		bottom: -6rpx;
		left: 50%;
		transform: translateX(-50%);
		width: 40rpx;
		height: 4rpx;
		border-radius: 6rpx;
		background: $bgColor;
		animation: a-m 0.3s;
	}

	@keyframes a-m {
		0% {
			width: 0rpx;
		}

		100% {
			width: 40rpx;
		}
	}

	.scroll {
		white-space: nowrap;
	}
</style>